Repository navigation
Fill the areas of {ggplot2} grobs with with_pattern() and export pattern geom helpers - #167
Merged
Merged
Conversation
…ttern::with_pattern()` (#158) Our geoms now draw the grob of the `{ggplot2}` geom they extend and fill each of its areas with a pattern in place instead of copying its grob-construction logic. The `draw_key_*_pattern()` functions likewise fill the areas of the corresponding `{ggplot2}` key glyphs. * Each area's fill, pattern, and border are now drawn in turn so overlapping areas stack correctly * `geom_ribbon_pattern()` and friends support a `fill` or `alpha` that varies along the ribbon * `geom_sf_pattern()` also fills each polygon of a `GEOMETRYCOLLECTION` * Bumps required version of `{gridpattern}` to v1.6.0-11 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`geom_point_pattern()` fills each point with a filled symbol (`shape` 21 to 25, its default is 21) with its own pattern. Points with other shapes are drawn as by `geom_point()`. Requires R (>= 4.2.0). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tests Use `layer_grob()` instead of `print()` to trigger the "Pattern aesthetics can not vary along a ribbon" error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Snapshots for the `gridpattern::with_pattern()` based geoms (#158), where each area's fill, pattern, and border are now drawn in turn, new `geom_point_pattern()` snapshots, and the previously stale `pattern_fill` snapshots. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* `make_GeomPattern()` (not exported yet) makes a pattern geom from a `{ggplot2}` geom:
it draws the parent geom's grob and fills each of its areas with the pattern of its row
(matched by its `rows` argument or else by tracing each area's fill back to its row).
* The `Layer` method of `gridpattern::with_pattern()` (registered but not re-exported)
makes a pattern layer from a layer e.g. `with_pattern(geom_rect(), pattern_fill = "blue")`,
and its `dotstackGrob` method fills the dots of `geom_dotplot()` when they are drawn.
* The pattern geoms now fill their areas with `with_pattern_aes()`
and their key glyphs with `with_pattern_key()`.
Requires `{gridpattern}` (>= 1.6.0-14).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Its presets are now `"row"` (was `"all"`), `"group"`, and `"trace"`. * `"constant"` is dropped: the geoms it was for (e.g. `GeomRibbon`) draw a single area per `draw_group()` call so `"group"` matches them, and `"group"` now checks that the pattern aesthetics don't vary within a group (as `"constant"` did). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its areas
`make_GeomPattern()`'s geoms now catch `{gridpattern}`'s `gridpattern_area_mismatch` error
and re-raise it (class `ggpattern_area_mismatch`, with it as the parent) naming the geom
and its `area_by` and suggesting `area_by = "trace"`,
also when the error is only raised when the grob is drawn (`delay = TRUE`).
Requires `{gridpattern}` (>= 1.6.0-15).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Pattern()`
* Only the data, panel parameters, and coord before any `...` are passed by position
e.g. `GeomViolin$draw_group(self, data, ..., quantile_gp, flipped_aes)`'s `quantile_gp`
was passed into `...` (so a violin's quantile line styling was ignored).
* They are now given `{ggplot2}`'s names (`data`, `panel_params`, `coord`)
which `Geom$parameters()` and `make_constructor()` leave out
e.g. for `treemapify::GeomTreemap` (which calls its panel parameters `panel_scales`)
`make_constructor()` no longer asks for a default `panel_scales`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ttern()` * `make_GeomPattern()` makes a pattern geom from (almost) any geom and the `Layer` method of `with_pattern()` makes a pattern layer from a layer e.g. `with_pattern(geom_contour_filled(), pattern_fill = "white")`. * Their `delay` argument is dropped: a grob with no areas when the panel is drawn (e.g. one that makes its areas in a `makeContent()` method) is now filled when it is drawn. * An `area_by` function is now also given the draw method's parameters it has arguments for (or all of them if it has `...`). * Filling areas other than rectangles, polygons, and paths requires R (>= 4.2.0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_pattern_aes()` (#156) * `with_pattern_aes()` fills the areas of a grob with the patterns of their rows of a layer's data and `with_pattern_key()` fills a legend key glyph with the key's pattern, for writing the draw methods of a pattern geom. * `default_pattern_aes()` returns the default pattern aesthetics for a pattern geom's `default_aes`. * New "Developing Pattern Geoms" vignette (`with_pattern()`, `make_GeomPattern()` and its `area_by`, and writing the draw methods yourself). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Nothing exported accepts a `polygon_df` (a data frame with `x`, `y`, and `id` columns).
To fill the areas of a grob with patterns see `with_pattern_aes()`.
* They now share a help page marked `@keywords internal`
and are no longer listed in the `{pkgdown}` reference index.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The `.Defunct()` stubs have been unexported since v0.4.2 so only the `ggpattern-defunct` help page (and its test) was left of them. * Also removes the (commented out) `ggpattern-deprecated` help page scaffold: deprecated functions are now marked `@keywords internal` instead. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…build`
`R CMD check` warned that `{treemapify}` is used in the tests but not declared.
Rather than add it to `Suggests` its test is now in a file in `.Rbuildignore`
so it is only run from a source checkout.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ction * It is for users rather than for developing new geoms so it moves to a new "Patterned layers" section after the geom functions. * Drops the "Re-exported functions" section (it listed a stray `reexports` beside `with_pattern()`). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 14, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #156, closes #158, closes #161.
Summary
Our geoms now draw the grob of the
{ggplot2}geom they extend and fill each of its areas with a pattern in place (usinggridpattern::with_pattern()), instead of copying{ggplot2}'s grob-construction logic. The same machinery is exported so pattern geoms can be made from other geoms, and the helpers it makes redundant are deprecated or removed.New features
make_GeomPattern()makes a pattern geom from (almost) any{ggplot2}(or extension) geom. Itsarea_byargument says how the areas are matched to the rows of the data ("row","group", a function, or"trace").gridpattern::with_pattern()is re-exported and has a newLayermethod e.g.with_pattern(geom_contour_filled(), pattern_fill = "white").with_pattern_aes(),with_pattern_key(), anddefault_pattern_aes()for writing the draw methods of a pattern geom, plus a new "Developing Pattern Geoms" vignette (Export helpers for third-party pattern geoms #156).geom_point_pattern()and itsdraw_key_point_pattern()key glyph.Changes to existing geoms (#158)
{ggplot2}draws its areas) instead of every border being drawn above every pattern.draw_key_polygon_pattern(),draw_key_boxplot_pattern(), anddraw_key_crossbar_pattern()now fill{ggplot2}'s own key glyphs, so key borders have the geom's border width and boxplot/crossbar keys respectorientationand the whisker, median, box, and staple parameters.filloralphathat varies along the ribbon.subgroupand ofgeom_sf_pattern();geom_sf_pattern()also fills each polygon of aGEOMETRYCOLLECTION.Deprecated and removed (#161)
create_polygon_df()andis_polygon_df()are soft-deprecated since nothing exported accepts apolygon_df. They share one help page marked@keywords internaland are no longer in the{pkgdown}reference index..Defunct()stubs (unexported since v0.4.2), theggpattern-defuncthelp page, and the commented outggpattern-deprecatedscaffold are removed.Housekeeping
{treemapify}test moves totests/testthat/test-with-pattern-treemapify.R, which is in.Rbuildignore, so{treemapify}need not be inSuggests(it is only run from a source checkout).with_pattern.Layer()gets its own "Patterned layers" section in the{pkgdown}reference index and the "Re-exported functions" section is dropped.Notes for review
{gridpattern}(>= 1.6.0-15) (installed viaRemotes: trevorld/gridpattern), so this cannot go to CRAN before{gridpattern}does.with_pattern()does not yet accept a list of layers (e.g. whatgeom_sf()returns); alistmethod has been proposed for{gridpattern}.Testing
{gridpattern}(428 passing) before the last three small changes (dropping the deprecated page's example, moving the{treemapify}test, and the{pkgdown}index); after them only thewith-patterntests were re-run (82 passing).pkgdown::check_pkgdown()reports no problems.R CMD checkhas not been re-run on the final commit.🤖 Generated with Claude Code